$(document).ready(function(){

	$('#headquater').chainSelect('#user','userchainselect.php',
	{ 
		after:function (target) //after request show the target combobox and hide the loading message
		{ 
			$(target).css("display","inline");
		}
	});
	
	$('#user').change(function(){

            var ids =this.value;

//alert(ids);
            if(ids == null || ids <1) { 
                ids=0; 
                //if(jQuery('#list').jqGrid('getGridParam','records') >0 ) { 
                    jQuery('#list').jqGrid('setGridParam',{url:'./ajax/mtada.php?q=1&id='+ids,page:1}); 
                    jQuery('#list').jqGrid('setCaption','TA / DA List:').trigger('reloadGrid');
                //} 
            } else { 
                jQuery('#list').jqGrid('setGridParam',{url:'./ajax/mtada.php?q=1&id='+ids,page:1}); 
                jQuery('#list').jqGrid('setCaption','TA / DA List:').trigger('reloadGrid'); 
            } 

        });

        jQuery('#list').jqGrid({
            url:'./ajax/mtada.php?q=1&id=0',
            datatype: 'xml',
            mtype: 'GET',
            colNames:['SN','Date', 'Visited Place','TA (Rs.)','DA (Rs.)','Others (Rs.)','Total (Rs.)','Remark'],
            colModel :[ 
            {name:'id', index:'id', width:25,sortable:false}, 
            {name:'visited_date', index:'visited_date', width:120, align:'left',sorttype:'text'}, 
            {name:'visit_place', index:'visit_place', width:50, align:'left',sortable:false}, 
            {name:'ta', index:'ta', width:60, align:'left',sortable:false}, 
            {name:'da', index:'da', width:50, align:'left',sortable:false}, 
            {name:'other', index:'other', width:40, align:'center',sortable:false}, 
            {name:'total', index:'total', width:40, align:'center',sortable:false}, 
            {name:'remark', index:'remark', width:40, align:'left',sortable:false}, 
            ],
            pager: '#pager',
            rowNum:8,
                width:500,
                height:175,
                hidegrid:false,
            rowList:[10,20,30],
            sortname: 'visited_date',
            sortorder: 'DESC',
            viewrecords: true,
            imgpath: '',
            caption: 'TA / DA List'
        }); 
        $('#user').change();	
});
